package utility;

import java.awt.Container;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

import core.Configuration;

public final class WindowManipulator {
	private static Dimension getScreenCenterPosition(Dimension parentSize, Dimension windowSize){		
		int x = (int) (parentSize.getWidth()/2 - windowSize.getWidth()/2);
		int y = (int) (parentSize.getHeight()/2 - windowSize.getHeight()/2);
		return new Dimension(x,y);
	}
	
	/**
	 * Move window to the center of screen
	 * @param window
	 */
	public static void movePositionToCenter(Container window){
		Dimension position = getScreenCenterPosition(User.getScreenResolution(),window.getSize());
		window.setLocation(position.width, position.height);
	}
	
	/**
	 * Move window to the center of parent Container
	 * @param parent
	 * @param window
	 */
	public static void movePositionToCenter(Container parent, Container window){
		Dimension position = getScreenCenterPosition(parent.getSize(),window.getSize());
		position.height += parent.getLocation().y;
		position.width += parent.getLocation().x;
		window.setLocation(position.width, position.height);
	}
	
	
	public static void addWindowIcon(JFrame parent){
		try {
			parent.setIconImage(ImageIO.read(new File(Configuration.MONOPOLY_SMALL_ICON_PATH)));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
}
